/*
Copyright (C) 2021-2025 Casa Xu (also Zhiyan Xu) from HIT

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef HARDWARE_LAYER_INC_LOS_SPI_H_
#define HARDWARE_LAYER_INC_LOS_SPI_H_

#include "HL_spi.h"
#include "HL_mibspi.h"

/* SPI端口号定义 */
#define LOS_SPI_NUM1 1U
#define LOS_SPI_NUM2 2U
#define LOS_SPI_NUM3 3U
#define LOS_SPI_NUM4 4U
#define LOS_SPI_NUM5 5U

/* SPI片选号定义 */
#define LOS_SPI_CS0 0U
#define LOS_SPI_CS1 1U
#define LOS_SPI_CS2 2U
#define LOS_SPI_CS3 3U
#define LOS_SPI_CS4 4U
#define LOS_SPI_CS5 5U
#define LOS_SPI_CSALL 100U

/* SPI错误类型判断 */
#define LOS_SPI_ERR_TRAN 1U
#define LOS_SPI_ERR_RECV 2U


void LOS_SPI_Init(void);
void LOS_SPI_Config(uint8_t SPI_NUM, uint8_t CPOL, uint8_t CPHA, uint32_t wordlen);
uint32_t LOS_SPI_Transmit(uint8_t SPI_NUM, uint32_t length, uint16_t * data);
uint32_t LOS_SPI_Receive(uint8_t SPI_NUM, uint32_t length, uint16_t * data);
uint32_t LOS_SPI_TR(uint8_t SPI_NUM, uint32_t length, uint16_t * data_t, uint16_t * data_r);
void LOS_SPI_ERR(uint8_t ERR_SIT);
uint16_t LOS_SPI_WriteReadByte(uint8_t SPI_NUM, uint16_t Byte, uint16_t CS_NUM);
uint16_t LOS_SPI_WriteReadLastByte(uint8_t  SPI_NUM, uint16_t Byte, uint16_t CS_NUM);
void LOS_SPI_Start(uint8_t SPI_NUM);
void LOS_SPI_Stop(uint8_t SPI_NUM);
uint16_t LOS_SPI_MEMS(uint16_t Bytes);


#endif /* HARDWARE_LAYER_INC_LOS_SPI_H_ */
